package com.training1.core.modules.service;


import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.math.BigDecimal;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;

import com.training1.core.common.exception.ExcelException;
import com.training1.core.common.global.signIn.LoginInfoUtil;
import com.training1.core.common.service.CrudService;
import com.training1.core.entity.BranchEntity;
import com.training1.core.entity.ChargeEntity;
import com.training1.core.entity.ContractDetEntity;
import com.training1.core.entity.MemberEntity;
import com.training1.core.entity.SystemParamEntity;
import com.training1.core.exception.BusinessException;
import com.training1.core.modules.dao.BranchDao;
import com.training1.core.modules.dao.ChargeDao;
import com.training1.core.modules.dao.MemberDao;
import com.training1.core.modules.dao.SystemSettingsDao;
import com.training1.util.ImportExcel;
import com.training1.util.SequenceNumberUtil;

@Service
@Transactional
public class BranchService extends CrudService<BranchDao,BranchEntity>{
	
	@Resource
	private BranchDao branchDao;
	
	/**
	 * 根据所有的分支机构
	 * @return
	 */
	public List<BranchEntity>  findListById(Map<String, Object> map) {
		
		
		List<BranchEntity> branches = branchDao.findList(map);
		
		return branches;
	}
	/**
	 * 根据所有的分支机构类型
	 * @return
	 */
	public List<BranchEntity>  findAllTypeName() {
		
		
		List<BranchEntity> branches = branchDao.findAllTypeName();
		for(BranchEntity branch : branches){
			if(branch.getOrgType().equals("1")){
				branch.setOrgTypeName("分公司");
			}else{
				branch.setOrgTypeName("总部");
			}
		}
		
		
		return branches;
	}
	/**
	 * 根据是否有该机构名
	 * @return
	 */
	public String checkOrgName(Map<String, Object> map) {
		String result = "1";
		
		BranchEntity branch = branchDao.checkOrgName(map);
		if(branch != null ){
			result = "0";
		}
		
		return result;
	}
	/**
	 * 根据总部是否存在   0存在 1不存在
	 * @return
	 */
	public String checkOrgType() {
		String result = "1";
		
		BranchEntity branch = branchDao.checkOrgType();
		if(branch != null ){
			result = "0";
		}
		
		return result;
	}
	
}